//
//  UIView+DoitInit.m
//  Pods
//
//  Created by Apple on 2022/11/4.
//

#import "UIView+DoitInit.h"
#import "UIView+FrameHelp.h"
#import <Masonry/Masonry.h>
#import <objc/runtime.h>

@interface UIView (DoitInit)

@property (nonatomic, copy) dispatch_block_t viewDoitInitBlock;

@end


@implementation UIView (DoitInit)

- (dispatch_block_t)viewDoitInitBlock {
    return objc_getAssociatedObject(self, _cmd);
}

- (void)setViewDoitInitBlock:(dispatch_block_t)viewDoitInitBlock {
    objc_setAssociatedObject(self, @selector(viewDoitInitBlock), viewDoitInitBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

+ (UIView * _Nonnull (^)(void))yc_init {
    return ^{
        return [self new];
    };
}

+ (UIView * _Nonnull (^)(CGRect))yc_initWithframe {
    return ^(CGRect frame){
        return [[self alloc] initWithFrame:frame];
    };
}

+ (UIView * _Nonnull (^)(UIColor *))yc_lineViewWithColor {
    return ^(UIColor *backgroundColor){
        UIView *lineView = [self new];
        lineView.yc_height = 0.75;
        lineView.backgroundColor = backgroundColor;
        return lineView;
    };
}

+ (UIView * _Nonnull (^)(UIColor *, CGFloat))yc_lineViewWithColorAndHeight {
    return ^(UIColor *backgroundColor, CGFloat height){
        UIView *lineView = UIView.yc_lineViewWithColor(backgroundColor);
        lineView.yc_height = height;
        return lineView;
    };
}

- (UIView * _Nonnull (^)(CGRect))yc_frame {
    return ^(CGRect frame){
        self.frame = frame;
        return self;
    };
}

- (UIView * _Nonnull (^)(UIColor *))yc_backgroundColor {
    return ^(UIColor *backgroundColor){
        self.backgroundColor = backgroundColor;
        return self;
    };
}

- (UIView * _Nonnull (^)(UIViewContentMode))yc_contentMode {
    return ^(UIViewContentMode contentMode){
        self.contentMode = contentMode;
        return self;
    };
}

- (UIView * _Nonnull (^)(BOOL))yc_hidden {
    return ^(BOOL hidden){
        self.hidden = hidden;
        return self;
    };
}

- (UIView * _Nonnull (^)(BOOL))yc_userInteractionEnabled {
    return ^(BOOL userInteractionEnabled){
        self.userInteractionEnabled = userInteractionEnabled;
        return self;
    };
}

- (UIView * _Nonnull (^)(CGFloat))yc_cornerRadius {
    return ^(CGFloat cornerRadius){
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = cornerRadius;
        return self;
    };
}

- (UIView * _Nonnull (^)(CGFloat, UIColor *))yc_borderWidthAndColor {
    return ^(CGFloat borderWidth, UIColor *borderColor){
        self.layer.borderColor = borderColor.CGColor;
        self.layer.borderWidth = borderWidth;
        return self;
    };
}

- (UIView * _Nonnull (^)(dispatch_block_t))yc_action {
    return ^(dispatch_block_t block){
        self.userInteractionEnabled = YES;
        self.viewDoitInitBlock = block;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClickAction)];
        [self addGestureRecognizer:tap];
        return self;
    };
}

- (void)tapClickAction {
    if (self.viewDoitInitBlock) {
        self.viewDoitInitBlock();
    }
}

@end



@implementation UIImageView (DoitInit)

+ (UIImageView * _Nonnull (^)(UIImage *))yc_initWithImage {
    return ^(UIImage *image){
        return [[self alloc] initWithImage:image];;
    };
}

+ (UIImageView * _Nonnull (^)(void))yc_init {
    return ^{
        return [self new];
    };
}

- (UIImageView * _Nonnull (^)(UIImage *))yc_image {
    return ^(UIImage *image){
        self.image = image;
        return self;
    };
}

@end



@implementation UILabel (DoitInit)

+ (UILabel * _Nonnull (^)(UIFont *font, UIColor *textColor, NSString *text))yc_initLabel {
    return ^(UIFont *font, UIColor *textColor, NSString *text){
        UILabel *label = [self new];
        label.text = text;
        label.font = font;
        label.textColor = textColor;
        return label;
    };
}

+ (UILabel * _Nonnull (^)(UIFont *, UIColor *))yc_initWithFontAndColor {
    return ^(UIFont *font, UIColor *textColor){
        return self.yc_initLabel(font, textColor, @"");
    };
}

+ (UILabel * _Nonnull (^)(void))yc_init {
    return ^{
        return [self new];
    };
}

- (UILabel * _Nonnull (^)(NSString *))yc_text {
    return ^(NSString *text){
        self.text = text;
        return self;
    };
}

- (UILabel * _Nonnull (^)(UIFont *))yc_font {
    return ^(UIFont *font){
        self.font = font;
        return self;
    };
}

- (UILabel * _Nonnull (^)(UIColor *))yc_textColor {
    return ^(UIColor *textColor){
        self.textColor = textColor;
        return self;
    };
}

- (UILabel * _Nonnull (^)(NSTextAlignment))yc_textAlignment {
    return ^(NSTextAlignment textAlignment){
        self.textAlignment = textAlignment;
        return self;
    };
}

- (UILabel * _Nonnull (^)(NSInteger))yc_numberOfLines {
    return ^(NSInteger numberOfLines){
        self.numberOfLines = numberOfLines;
        return self;
    };
}

@end



@implementation UITextField (DoitInit)

+ (UITextField * _Nonnull (^)(UIFont *, UIColor *, NSString *, NSString *))yc_initTextField {
    return ^(UIFont *font, UIColor *textColor, NSString *text, NSString *placeholder){
        UITextField *textField = [self new];
        textField.text = text;
        textField.font = font;
        textField.textColor = textColor;
        textField.placeholder = placeholder;
        return textField;
    };
}

+ (UITextField * _Nonnull (^)(UIFont *, UIColor *))yc_initWithFontAndColor {
    return ^(UIFont *font, UIColor *textColor){
        return self.yc_initTextField(font, textColor, @"", @"");
    };
}

+ (UITextField * _Nonnull (^)(void))yc_init {
    return ^{
        return [self new];
    };
}

- (UITextField * _Nonnull (^)(NSString *))yc_text {
    return ^(NSString *text){
        self.text = text;
        return self;
    };
}

- (UITextField * _Nonnull (^)(NSAttributedString *))yc_attributedText {
    return ^(NSAttributedString *attributedText){
        self.attributedText = attributedText;
        return self;
    };
}

- (UITextField * _Nonnull (^)(NSString *))yc_placeholder {
    return ^(NSString *placeholder){
        self.placeholder = placeholder;
        return self;
    };
}

- (UITextField * _Nonnull (^)(UIFont *))yc_font {
    return ^(UIFont *font){
        self.font = font;
        return self;
    };
}

- (UITextField * _Nonnull (^)(UIColor *))yc_textColor {
    return ^(UIColor *textColor){
        self.textColor = textColor;
        return self;
    };
}

- (UITextField * _Nonnull (^)(NSTextAlignment))yc_textAlignment {
    return ^(NSTextAlignment textAlignment){
        self.textAlignment = textAlignment;
        return self;
    };
}

- (UITextField * _Nonnull (^)(UITextBorderStyle))yc_borderStyle {
    return ^(UITextBorderStyle borderStyle){
        self.borderStyle = borderStyle;
        return self;
    };
}

- (UITextField * _Nonnull (^)(id<UITextFieldDelegate>))yc_delegate {
    return ^(id<UITextFieldDelegate> delegate){
        self.delegate = delegate;
        return self;
    };
}

@end



@implementation UITextView (DoitInit)

+ (UITextView * _Nonnull (^)(UIFont *, UIColor *, NSString *))yc_initTextView {
    return ^(UIFont *font, UIColor *textColor, NSString *text){
        UITextView *textView = [self new];
        textView.text = text;
        textView.font = font;
        textView.textColor = textColor;
        return textView;
    };
}

+ (UITextView * _Nonnull (^)(UIFont *, UIColor *))yc_initWithFontAndColor {
    return ^(UIFont *font, UIColor *textColor){
        return self.yc_initTextView(font, textColor, @"");
    };
}

+ (UITextView * _Nonnull (^)(void))yc_init {
    return ^{
        return [self new];
    };
}

- (UITextView * _Nonnull (^)(BOOL))yc_editable {
    return ^(BOOL editable){
        self.editable = editable;
        return self;
    };
}

- (UITextView * _Nonnull (^)(NSString *))yc_text {
    return ^(NSString *text){
        self.text = text;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIFont *))yc_font {
    return ^(UIFont *font){
        self.font = font;
        return self;
    };
}

- (UITextView * _Nonnull (^)(UIColor *))yc_textColor {
    return ^(UIColor *textColor){
        self.textColor = textColor;
        return self;
    };
}

- (UITextView * _Nonnull (^)(NSTextAlignment))yc_textAlignment {
    return ^(NSTextAlignment textAlignment){
        self.textAlignment = textAlignment;
        return self;
    };
}

- (UITextView * _Nonnull (^)(id<UITextViewDelegate>))yc_delegate {
    return ^(id<UITextViewDelegate> delegate){
        self.delegate = delegate;
        return self;
    };
}

@end




@implementation UIButton (DoitInit)

+ (UIButton * _Nonnull (^)(NSString *, UIFont *, UIColor *))yc_initWithTitle {
    return ^(NSString *title, UIFont *font, UIColor *titleColor){
        UIButton *btn = [self new];
        [btn setTitle:title forState:UIControlStateNormal];
        [btn setTitleColor:titleColor forState:UIControlStateNormal];
        [btn.titleLabel setFont:font];
        return btn;
    };
}

+ (UIButton * _Nonnull (^)(UIImage *, UIImage *))yc_initWithStateImage {
    return ^(UIImage *normalImage, UIImage *selectedImage){
        UIButton *btn = [self new];
        [btn setImage:normalImage forState:UIControlStateNormal];
        [btn setImage:selectedImage forState:UIControlStateSelected];
        return btn;
    };
}

+ (UIButton * _Nonnull (^)(UIImage *))yc_initWithImage {
    return ^(UIImage *image){
        UIButton *btn = [self new];
        [btn setImage:image forState:UIControlStateNormal];
        return btn;
    };
}

+ (UIButton * _Nonnull (^)(void))yc_init {
    return ^{
        return [self new];
    };
}

- (UIButton * _Nonnull (^)(UIFont *))yc_font {
    return ^(UIFont *font){
        self.titleLabel.font = font;
        return self;
    };
}

- (UIButton * _Nonnull (^)(NSString *))yc_normalTitle {
    return ^(NSString *title){
        [self setTitle:title forState:UIControlStateNormal];
        return self;
    };
}

- (UIButton * _Nonnull (^)(NSString *))yc_selectedTitle {
    return ^(NSString *title){
        [self setTitle:title forState:UIControlStateSelected];
        return self;
    };
}

- (UIButton * _Nonnull (^)(NSString *))yc_highlightedTitle {
    return ^(NSString *title){
        [self setTitle:title forState:UIControlStateHighlighted];
        return self;
    };
}

- (UIButton * _Nonnull (^)(NSString *))yc_disabledTitle {
    return ^(NSString *title){
        [self setTitle:title forState:UIControlStateDisabled];
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIImage *))yc_normalImage {
    return ^(UIImage *image){
        [self setImage:image forState:UIControlStateNormal];
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIImage *))yc_selectedImage {
    return ^(UIImage *image){
        [self setImage:image forState:UIControlStateSelected];
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIImage *))yc_highlightedImage {
    return ^(UIImage *image){
        [self setImage:image forState:UIControlStateHighlighted];
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIImage *))yc_disabledImage {
    return ^(UIImage *image){
        [self setImage:image forState:UIControlStateDisabled];
        return self;
    };
}
 
- (UIButton * _Nonnull (^)(UIColor *))yc_normalTitleColor {
    return ^(UIColor *color){
        [self setTitleColor:color forState:UIControlStateNormal];
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIColor *))yc_selectedTitleColor {
    return ^(UIColor *color){
        [self setTitleColor:color forState:UIControlStateSelected];
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIColor *))yc_highlightedTitleColor {
    return ^(UIColor *color){
        [self setTitleColor:color forState:UIControlStateHighlighted];
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIColor *))yc_disabledTitleColor {
    return ^(UIColor *color){
        [self setTitleColor:color forState:UIControlStateDisabled];
        return self;
    };
}

- (UIButton * _Nonnull (^)(id, SEL))yc_targetAction {
    return ^(id target, SEL action){
        [self addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
        return self;
    };
}

@end



@implementation UIControl (DoitInit)

- (UIControl * _Nonnull (^)(BOOL))yc_enabled {
    return ^(BOOL enabled){
        self.enabled = enabled;
        return self;
    };
}

- (UIControl * _Nonnull (^)(BOOL))yc_selected {
    return ^(BOOL selected){
        self.selected = selected;
        return self;
    };
}

- (UIControl * _Nonnull (^)(BOOL))yc_highlighted {
    return ^(BOOL highlighted){
        self.highlighted = highlighted;
        return self;
    };
}

- (UIControl * _Nonnull (^)(UIControlContentVerticalAlignment))yc_contentVerticalAlignment {
    return ^(UIControlContentVerticalAlignment contentVerticalAlignment){
        self.contentVerticalAlignment = contentVerticalAlignment;
        return self;
    };
}

- (UIControl * _Nonnull (^)(UIControlContentHorizontalAlignment))yc_contentHorizontalAlignment {
    return ^(UIControlContentHorizontalAlignment contentHorizontalAlignment){
        self.contentHorizontalAlignment = contentHorizontalAlignment;
        return self;
    };
}

@end



@implementation UITableView (DoitInit)

+ (UITableView * _Nonnull (^)(CGRect, UITableViewStyle))yc_initWithStyle {
    return ^(CGRect frame, UITableViewStyle style){
        return [[self alloc] initWithFrame:frame style:style];
    };
}

+ (UITableView * _Nonnull (^)(void))yc_init {
    return ^{
        return [self new];
    };
}

- (UITableView * _Nonnull (^)(id target))yc_delegate {
    return ^(id target){
        self.delegate = target;
        self.dataSource = target;
        return self;
    };
}

- (UITableView * _Nonnull (^)(UIView *))yc_tableHeaderView {
    return ^(UIView *view){
        self.tableHeaderView = view;
        return self;
    };
}

- (UITableView * _Nonnull (^)(UIView *))yc_tableFooterView {
    return ^(UIView *view){
        self.tableFooterView = view;
        return self;
    };
}

- (UITableView * _Nonnull (^)(CGFloat))yc_rowHeight {
    return ^(CGFloat rowHeight){
        self.rowHeight = rowHeight;
        return self;
    };
}

- (UITableView * _Nonnull (^)(CGFloat))yc_sectionHeaderHeight {
    return ^(CGFloat sectionHeaderHeight){
        self.sectionHeaderHeight = sectionHeaderHeight;
        return self;
    };
}

- (UITableView * _Nonnull (^)(CGFloat))yc_sectionFooterHeight {
    return ^(CGFloat sectionFooterHeight){
        self.sectionFooterHeight = sectionFooterHeight;
        return self;
    };
}

- (UITableView * _Nonnull (^)(CGFloat))yc_estimatedRowHeight {
    return ^(CGFloat estimatedRowHeight){
        self.estimatedRowHeight = estimatedRowHeight;
        return self;
    };
}

- (UITableView * _Nonnull (^)(CGFloat))yc_estimatedSectionHeaderHeight {
    return ^(CGFloat estimatedSectionHeaderHeight){
        self.estimatedSectionHeaderHeight = estimatedSectionHeaderHeight;
        return self;
    };
}

- (UITableView * _Nonnull (^)(CGFloat))yc_estimatedSectionFooterHeight {
    return ^(CGFloat estimatedSectionFooterHeight){
        self.estimatedSectionFooterHeight = estimatedSectionFooterHeight;
        self.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        return self;
    };
}

- (UITableView * _Nonnull (^)(void))yc_noneSeparator {
    return ^{
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        return self;
    };
}

- (UITableView * _Nonnull (^)(UIColor *))yc_separatorColor {
    return ^(UIColor *color){
        self.separatorColor = color;
        return self;
    };
}

- (UITableView * _Nonnull (^)(UIEdgeInsets))yc_contentInset {
    return ^(UIEdgeInsets contentInset){
        self.contentInset = contentInset;
        return self;
    };
}

- (UITableView * _Nonnull (^)(CGFloat))yc_contentInsetInTop {
    return ^(CGFloat top){
        self.contentInset = UIEdgeInsetsMake(top, 0, 0, 0);
        return self;
    };
}

- (UITableView * _Nonnull (^)(UIEdgeInsets))yc_separatorInset {
    return ^(UIEdgeInsets separatorInset){
        self.separatorInset = separatorInset;
        return self;
    };
}

- (UITableView * _Nonnull (^)(CGFloat, CGFloat))yc_separatorLeftAndRight {
    return ^(CGFloat left, CGFloat right){
        self.separatorInset = UIEdgeInsetsMake(0, left, 0, right);
        return self;
    };
}

- (UITableView * _Nonnull (^)(NSString *))yc_registerClassWithCellName {
    return ^(NSString *className){
        [self registerClass:NSClassFromString(className) forCellReuseIdentifier:className];
        return self;
    };
}

@end



@implementation UIView (Constraints)

- (UIView * _Nonnull (^)(UIEdgeInsets))yc_constraint_make_edge {
    return ^(UIEdgeInsets edgeInsets){
        if (UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, edgeInsets)) {
            [self mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(self.superview);
            }];
        } else {
            [self mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(@(edgeInsets.top));
                make.left.equalTo(@(edgeInsets.left));
                make.bottom.equalTo(@(-edgeInsets.bottom));
                make.right.equalTo(@(-edgeInsets.right));
            }];
        }
        
        return self;
    };
}

- (UIView * _Nonnull (^)(YCConstraintPosition, UIView *))yc_constraint_make_same {
    return ^(YCConstraintPosition position, UIView *view){
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            switch (position) {
                case YCConstraintPosition_Top:
                    make.top.equalTo(view);
                    break;
                case YCConstraintPosition_Bottom:
                    make.bottom.equalTo(view);
                    break;
                case YCConstraintPosition_Left:
                    make.left.equalTo(view);
                    break;
                case YCConstraintPosition_Right:
                    make.right.equalTo(view);
                    break;
                case YCConstraintPosition_CenterX:
                    make.centerX.equalTo(view);
                    break;
                case YCConstraintPosition_CenterY:
                    make.centerY.equalTo(view);
                    break;
                case YCConstraintPosition_Center:
                    make.center.equalTo(view);
                    break;
                case YCConstraintPosition_Width:
                    make.width.equalTo(view);
                    break;
                case YCConstraintPosition_Height:
                    make.height.equalTo(view);
                    break;
                case YCConstraintPosition_Size:
                    make.size.equalTo(view);
                    break;
                    
                default:
                    break;
            }
        }];
        
        return self;
    };
}

- (UIView * _Nonnull (^)(YCConstraintCorner, CGRect))yc_constraint_make_corner {
    return ^(YCConstraintCorner corner, CGRect rect){
        if (!CGRectEqualToRect(CGRectZero, rect)) {
            [self mas_makeConstraints:^(MASConstraintMaker *make) {
                switch (corner) {
                    case YCConstraintCorner_Left_Top:
                    {
                        make.top.equalTo(@(rect.origin.y));
                        make.left.equalTo(@(rect.origin.x));
                    }
                        break;
                    case YCConstraintCorner_Left_Bottom:
                    {
                        make.bottom.equalTo(@(-(rect.origin.y)));
                        make.left.equalTo(@(rect.origin.x));
                    }
                        break;
                    case YCConstraintCorner_Right_Top:
                    {
                        make.top.equalTo(@(rect.origin.y));
                        make.right.equalTo(@(-(rect.origin.x)));
                    }
                        break;
                    case YCConstraintCorner_Right_Bottom:
                    {
                        make.bottom.equalTo(@(-(rect.origin.y)));
                        make.right.equalTo(@(-(rect.origin.x)));
                    }
                        break;
                    case YCConstraintCorner_Left_Center:
                    {
                        make.centerY.equalTo(self.superview);
                        make.left.equalTo(@(rect.origin.x));
                    }
                        break;
                    case YCConstraintCorner_Right_Center:
                    {
                        make.centerY.equalTo(self.superview);
                        make.right.equalTo(@(-(rect.origin.x)));
                    }
                        break;
                    case YCConstraintCorner_Center_Top:
                    {
                        make.top.equalTo(@(rect.origin.y));
                        make.centerX.equalTo(self.superview);
                    }
                        break;
                    case YCConstraintCorner_Center_Bottom:
                    {
                        make.bottom.equalTo(@(-(rect.origin.y)));
                        make.centerX.equalTo(self.superview);
                    }
                        break;
                        
                    default:
                        break;
                }
                
                make.size.mas_equalTo(rect.size);
            }];
        }
        
        return self;
    };
}

- (UIView * _Nonnull (^)(YCConstraintPosition, UIView *, CGFloat))yc_constraint_make_space {
    return ^(YCConstraintPosition position, UIView *view, CGFloat space){
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            switch (position) {
                case YCConstraintPosition_Top:
                    make.bottom.equalTo(view.mas_top).offset(-(space));
                    break;
                    
                case YCConstraintPosition_Bottom:
                    make.top.equalTo(view.mas_bottom).offset(space);
                    break;
                    
                case YCConstraintPosition_Left:
                    make.right.equalTo(view.mas_left).offset(-(space));
                    break;
                    
                case YCConstraintPosition_Right:
                    make.left.equalTo(view.mas_right).offset(space);
                    break;
                    
                default:
                    break;
            }
        }];
        
        return self;
    };
}

- (UIView * _Nonnull (^)(YCConstraintPosition, UIView *, CGFloat))yc_constraint_make_offset {
    return ^(YCConstraintPosition position, UIView *view, CGFloat offset){
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            switch (position) {
                case YCConstraintPosition_Top:
                    make.bottom.equalTo(view.mas_bottom).offset(-(offset));
                    break;
                    
                case YCConstraintPosition_Bottom:
                    make.top.equalTo(view.mas_top).offset(offset);
                    break;
                    
                case YCConstraintPosition_Left:
                    make.right.equalTo(view.mas_right).offset(-(offset));
                    break;
                    
                case YCConstraintPosition_Right:
                    make.left.equalTo(view.mas_left).offset(offset);
                    break;
                    
                default:
                    break;
            }
        }];
        
        return self;
    };
}

- (UIView * _Nonnull (^)(UIView *, CGFloat))yc_constraint_make_multiple_width {
    return ^(UIView *view, CGFloat multiple){
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(view.mas_width).multipliedBy(multiple);
        }];
        
        return self;
    };
}

- (UIView * _Nonnull (^)(UIView *, CGFloat))yc_constraint_make_multiple_height {
    return ^(UIView *view, CGFloat multiple){
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(view.mas_height).multipliedBy(multiple);
        }];
        
        return self;
    };
}

- (UIView * _Nonnull (^)(CGFloat))yc_constraint_make_aspectRatio {
    return ^(CGFloat multiple){
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(self.mas_height).multipliedBy(multiple);
        }];
        
        return self;
    };
}

- (UIView * _Nonnull (^)(YCConstraintSpace, CGFloat))yc_constraint_make_equal {
    return ^(YCConstraintSpace space, CGFloat value){
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            switch (space) {
                case YCConstraintSpace_Top:
                    make.top.equalTo(@(value));
                    break;
                case YCConstraintSpace_Bottom:
                    make.bottom.equalTo(@(-value));
                    break;
                case YCConstraintSpace_Left:
                    make.left.equalTo(@(value));
                    break;
                case YCConstraintSpace_Right:
                    make.right.equalTo(@(-value));
                    break;
                case YCConstraintSpace_Width:
                    make.width.equalTo(@(value));
                    break;
                case YCConstraintSpace_Height:
                    make.height.equalTo(@(value));
                    break;
                case YCConstraintSpace_Width_Height:
                    make.width.height.equalTo(@(value));
                    break;
                case YCConstraintSpace_Left_Top:
                    make.left.top.equalTo(@(value));
                    break;
                case YCConstraintSpace_Left_Bottom:
                {
                    make.left.equalTo(@(value));
                    make.bottom.equalTo(@(-value));
                }
                    break;
                case YCConstraintSpace_Left_Right:
                {
                    make.left.equalTo(@(value));
                    make.right.equalTo(@(-value));
                }
                    break;
                case YCConstraintSpace_Right_Top:
                {
                    make.top.equalTo(@(value));
                    make.right.equalTo(@(-value));
                }
                    break;
                case YCConstraintSpace_Right_Bottom:
                {
                    make.bottom.equalTo(@(-value));
                    make.right.equalTo(@(-value));
                }
                    break;
                case YCConstraintSpace_Top_Bottom:
                {
                    make.top.equalTo(@(value));
                    make.bottom.equalTo(@(-value));
                }
                    break;
                    
                default:
                    break;
            }
        }];
        
        return self;
    };
}

- (UIView * _Nonnull (^)(YCConstraintSpace, CGFloat))yc_constraint_remake_equal {
    return ^(YCConstraintSpace space, CGFloat value){
        [self mas_remakeConstraints:^(MASConstraintMaker *make) {
            switch (space) {
                case YCConstraintSpace_Top:
                    make.top.equalTo(@(value));
                    break;
                case YCConstraintSpace_Bottom:
                    make.bottom.equalTo(@(-value));
                    break;
                case YCConstraintSpace_Left:
                    make.left.equalTo(@(value));
                    break;
                case YCConstraintSpace_Right:
                    make.right.equalTo(@(-value));
                    break;
                case YCConstraintSpace_Width:
                    make.width.equalTo(@(value));
                    break;
                case YCConstraintSpace_Height:
                    make.height.equalTo(@(value));
                    break;
                case YCConstraintSpace_Width_Height:
                    make.width.height.equalTo(@(value));
                    break;
                case YCConstraintSpace_Left_Top:
                    make.left.top.equalTo(@(value));
                    break;
                case YCConstraintSpace_Left_Bottom:
                {
                    make.left.equalTo(@(value));
                    make.bottom.equalTo(@(-value));
                }
                    break;
                case YCConstraintSpace_Left_Right:
                {
                    make.left.equalTo(@(value));
                    make.right.equalTo(@(-value));
                }
                    break;
                case YCConstraintSpace_Right_Top:
                {
                    make.top.equalTo(@(value));
                    make.right.equalTo(@(-value));
                }
                    break;
                case YCConstraintSpace_Right_Bottom:
                {
                    make.bottom.equalTo(@(-value));
                    make.right.equalTo(@(-value));
                }
                    break;
                case YCConstraintSpace_Top_Bottom:
                {
                    make.top.equalTo(@(value));
                    make.bottom.equalTo(@(-value));
                }
                    break;
                    
                default:
                    break;
            }
        }];
        
        return self;
    };
}

- (UIView * _Nonnull (^)(YCConstraintSpace, CGFloat))yc_constraint_update_equal {
    return ^(YCConstraintSpace space, CGFloat value){
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            switch (space) {
                case YCConstraintSpace_Top:
                    make.top.equalTo(@(value));
                    break;
                case YCConstraintSpace_Bottom:
                    make.bottom.equalTo(@(-value));
                    break;
                case YCConstraintSpace_Left:
                    make.left.equalTo(@(value));
                    break;
                case YCConstraintSpace_Right:
                    make.right.equalTo(@(-value));
                    break;
                case YCConstraintSpace_Width:
                    make.width.equalTo(@(value));
                    break;
                case YCConstraintSpace_Height:
                    make.height.equalTo(@(value));
                    break;
                case YCConstraintSpace_Width_Height:
                    make.width.height.equalTo(@(value));
                    break;
                case YCConstraintSpace_Left_Top:
                    make.left.top.equalTo(@(value));
                    break;
                case YCConstraintSpace_Left_Bottom:
                {
                    make.left.equalTo(@(value));
                    make.bottom.equalTo(@(-value));
                }
                    break;
                case YCConstraintSpace_Left_Right:
                {
                    make.left.equalTo(@(value));
                    make.right.equalTo(@(-value));
                }
                    break;
                case YCConstraintSpace_Right_Top:
                {
                    make.top.equalTo(@(value));
                    make.right.equalTo(@(-value));
                }
                    break;
                case YCConstraintSpace_Right_Bottom:
                {
                    make.bottom.equalTo(@(-value));
                    make.right.equalTo(@(-value));
                }
                    break;
                case YCConstraintSpace_Top_Bottom:
                {
                    make.top.equalTo(@(value));
                    make.bottom.equalTo(@(-value));
                }
                    break;
                    
                default:
                    break;
            }
        }];
        
        return self;
    };
}

@end
